package com.cacy.controller;

import com.cacy.pojo.Emp;
import com.cacy.pojo.Result;
import com.cacy.utils.XmlParserUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Project: test_maven_20250317
 * Package: com.cacy.controller
 * Class:   EmpController
 * Description:
 *
 * @Date: 2025/3/21 周五
 * @Time: 20:42
 * @Author: 凯齐
 */

@RestController
public class EmpController {
    @RequestMapping("/listEmp")
    public Result list() {
        String file = this.getClass().getClassLoader().getResource("emp.xml").getFile();
        System.out.println(file);
        List<Emp> empList = XmlParserUtils.parse(file, Emp.class);

        empList.stream().forEach(emp -> {
            String gender = emp.getGender();
            if ("1".equals(gender)) {
                emp.setGender("男");
            }else if ("2".equals(gender)) {
                emp.setGender("女");
            }

            String job = emp.getJob();
            if ("1".equals(job)) {
                emp.setJob("讲师");
            }else if ("2".equals(job)) {
                emp.setJob("班主任");
            }else if ("3".equals(job)) {
                emp.setJob("就业指导");
            }
        });

        return Result.success(empList);
    }
}
